package cn.edu.scau.cmi.lixiaoyuan.adapter.fx;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import cn.edu.scau.cmi.lixiaoyuan.adapter.AdapterOfClass;
import cn.edu.scau.cmi.lixiaoyuan.adapter.Student;
import cn.edu.scau.cmi.lixiaoyuan.multition.Marshal;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Labeled;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class Controller implements Initializable{
	public List<Student> studentList = new ArrayList<Student>();
	public List<Integer> stuId = new ArrayList<Integer>();
	public String strClass = "";
	
	 @FXML
	 private TextField stu_id;
	 @FXML
	 private TextField stu_name;
	 @FXML
	 private Button create;
	 @FXML
	 private Button print;
	 @FXML
	 private TextArea TextArea;
	 @FXML
	 private TextArea TextArea2;
	 
	 public void initialize(URL location, ResourceBundle resources) {

	       // TODO (don't really need to do anything here).

	   }
	 public void addStudent(ActionEvent event) {
	       Student student = new Student();
	       student.setName(stu_name.getText());
	       student.setId(Integer.parseInt(stu_id.getText()));
	       stuId.add(student.getId());
	       studentList.add(student);
	      
	   }
	 public void showData(ActionEvent event) {
		
		 AdapterOfClass adapter = new AdapterOfClass();
		 List<Student> result =adapter.sortString(stuId, studentList);
	
		 strClass = "";
		 strClass =strClass+"--------------------"+"\r\n";
		 for(Student stu:result) {
			 strClass =strClass + stu.toString()+"\r\n";
		 }
		 TextArea.setText(strClass);
	     TextArea2.setText(strClass);
			
		 
	 }
}
